package com.longjianghuasheng.logistics.business.order.adapter

import android.annotation.SuppressLint
import android.content.res.ColorStateList
import android.view.View
import com.blankj.utilcode.util.ColorUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.longjianghuasheng.logistics.R
import com.longjianghuasheng.logistics.databinding.ItemDriverOrderBinding
import com.longjianghuasheng.logistics.entity.Order
import com.longjianghuasheng.logistics.ext.loadUrl

class DriverOrderAdapter :
    BaseQuickAdapter<Order, BaseDataBindingHolder<ItemDriverOrderBinding>>(R.layout.item_driver_order) {
    var clickListener = { id: Int, btnText: String ->

    }

    var phoneListener = { view: View ->

    }

    @SuppressLint("SetTextI18n")
    override fun convert(holder: BaseDataBindingHolder<ItemDriverOrderBinding>, item: Order) {
        holder.dataBinding?.run {

            ivPhone.setOnClickListener(phoneListener)
            tvStatus.text = when (item.status) {
                1 -> "已接单"
                2 -> "进行中"
                3 -> "已完成"
                else -> ""
            }

            btnCancel.setOnClickListener {
                clickListener.invoke(item.id ?: 0, btnCancel.text.toString())
            }
            btnCancel.text = when (item.status) {
                1 -> CANCEL_APPLY_FOR
                2 -> CANCEL_APPLICATION_FINISHED
                3 -> CANCEL_DELETE_THE_ORDER
                else -> ""
            }

            btnCancel.backgroundTintList = ColorStateList.valueOf(
                ColorUtils.getColor(
                    when (item.status) {
                        1 -> R.color.redDD
                        2 -> R.color.yellowF9
                        3 -> R.color.grayB2
                        else -> R.color.btnColor
                    }
                )
            )



            ivPic.loadUrl(item.picurl)

            tvTitle.text = item.names

            tvOrderNum.text = "订单编号：${item.trade_no}"
            tvOrderDate.text = "下单日期：${item.create_time}"
        }
    }

    companion object {

        const val CANCEL_APPLY_FOR = "取消申请"
        const val CANCEL_APPLICATION_FINISHED = "完成申请"
        const val CANCEL_DELETE_THE_ORDER = "删除订单"
    }
}